myApp.onPageInit('message-list', function (page) {
    console.log("onPageInit " + page.name);

    var list = $$(page.container).find('.list-block'),
        empty = $$(page.container).find('.empty-view'),
        refreshContainer = $$(page.container).find('.pull-to-refresh-content');
    list.data('request', null);
    list.data('lastpage', false);
    list.data('nextpage', 0);

    function loadPage() {
        var refresing = list.data('nextpage') == 0,
            req = true;
        $$.getJSONP(SERVER_PATH + 'getMessageCenterList.do', {num: -1}, function (json) {
            if (json.code == 1) {
                list.data('nextpage', list.data('nextpage') + 1);

                if (refresing) {
                    list.find('ul').children().remove();
                }

                $$.each(json.results, function (index, value) {
                    if (value.isLastPage) {
                        list.data('lastpage', true);
                    }

                    preprocessData('MessageCenter', value);
                    var html = Template7.templates.messageTemplate(value);
                    list.find('ul').append(html);
                });
                empty[list.find('ul').children().length > 0 ? 'hide' : 'show']();
            }

            list.data('request', null);
            if (refresing) {
                myApp.pullToRefreshDone();
            }
        });
        list.data('request', req);
    }

    //$$(page.container).find('.infinite-scroll').on('infinite', function () {
    //    if (list.data('lastpage') || list.data('request')) {
    //        return;
    //    }
    //
    //    loadPage();
    //});
    refreshContainer.on('refresh', function () {
        var request = list.data('request');
        if (request) {
            request.abort();
        }
        list.data('request', null);
        list.data('lastpage', false);
        list.data('nextpage', 0);
        loadPage();
    });
    myApp.pullToRefreshTrigger(refreshContainer);

    list.on('click', '.item-link', function() {
        myApp.alert('该功能暂未开放', '移动QA');
    });
});